%%%-----------------------------------
%%% @Module  : pt_16
%%% @Author  : kxp
%%% @Created : 2016.08.19
%%% @Description: 10帐户信息
%%%-----------------------------------
-module(pt_16).
-export([read/2, write/2]).
-include("common.hrl").
-include("proto_all.hrl").

%%
%%客户端 -> 服务端 ----------------------------
%%

%%16000请求进入房间
read(16000, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_join_room, Bin),	
	{c2s_join_room ,RoomId,UpGrade} = ClientData,
    {ok, [RoomId,UpGrade]};

%% 16005玩家牌局操作2:抢地主，3:明牌/加倍
read(16005, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_player_choose_state, Bin),	
	{c2s_player_choose_state ,State,StatePos, StateType} = ClientData,
    {ok, [State,StatePos, StateType]};

%% 16005玩家出牌
read(16006, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_player_play_cards, Bin),	
	{c2s_player_play_cards ,Cards,Laizis} = ClientData,
    {ok, [Cards,Laizis]};

%% 16009玩家重新开始
read(16009, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_player_restart, Bin),	
	{c2s_player_restart, Uid, Isopen} = ClientData,
    {ok, [Uid, Isopen]};

%% 16010玩家退出斗地主
read(16010, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_player_leave, Bin),	
	{c2s_player_leave, Uid} = ClientData,
    {ok, [Uid]};

%% 16012 玩家设置托管
read(16012, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_player_trust, Bin),	
	{c2s_player_trust, State} = ClientData,
    {ok, [State]};

%% 16013 玩家发表情
read(16013, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_player_emoticon, Bin),	
	{c2s_player_emoticon, Id, Pos} = ClientData,
    {ok, [Id, Pos]};

%% 16014 获取比赛场信息
read(16014, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_get_match_info, Bin),	
	{c2s_get_match_info, RoomType} = ClientData,
    {ok, [RoomType]};

%% 16015 报名参加比赛场
read(16015, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_enroll_match, Bin),	
	{c2s_enroll_match, RoomId} = ClientData,
    {ok, [RoomId]};

%% 16017 取消报名比赛场
read(16017, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_cancel_match, Bin),	
	{c2s_cancel_match, RoomId} = ClientData,
    {ok, [RoomId]};

%% 16019获取比赛局数信息 
read(16019, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_get_match_turn_info, Bin),	
	{c2s_get_match_turn_info, RoomId} = ClientData,
    {ok, [RoomId]};

%% 16024 使用记牌器 
read(16024, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_poke_use_note, Bin),	
	{c2s_poke_use_note, Uid} = ClientData,
    {ok, [Uid]};

%% 16027 获取房间人数 
read(16027, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_poke_room_num, Bin),	
	{c2s_poke_room_num, Uid} = ClientData,
    {ok, [Uid]};

%% 16028 玩家触发技能buff
read(16028, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_trigger_skill, Bin),	
	{c2s_trigger_skill, SkillId, BuffType, Data} = ClientData,
    {ok, [SkillId, BuffType, Data]};

%% 16030 玩家准备开始实物大奖赛
read(16030, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_ready_match, Bin),	
	{c2s_ready_match, RoomId} = ClientData,
    {ok, [RoomId]};

%% 16031 透视卡
read(16031, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_poke_use_show, Bin),  
    {ok, [ClientData]};

%% 退出配桌
read(16033, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_poke_table_notify, Bin),  
    {c2s_poke_table_notify,Uid} = ClientData,
    {ok, [Uid]};

read(_Cmd, _R) ->
    ?ERROR_MSG("~s pt_10 reading cmd_[~p], Data:~p~n",[misc:time_format(game_timer:now()), _Cmd, _R]),
    {error, no_match}.

%%
%%服务端 -> 客户端 ------------------------------------
%%

%% 16000请求进入房间
write(16000, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_join_room, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16000, ServerData)};

%% 16001玩家进入牌局
write(16001, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_join_table, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16001, ServerData)};

%% 16002牌局开始
write(16002, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_table_start, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16002, ServerData)};

%% 16003系统发牌
write(16003, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_table_dealing, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16003, ServerData)};

%% 16004牌局状态信息，通知玩家倒计时
write(16004, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_table_state, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16004, ServerData)};

%% 16005玩家牌局操作
write(16005, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_player_choose_state, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16005, ServerData)};

%% 16006玩家出牌
write(16006, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_player_play_cards, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16006, ServerData)};

%% 16007 牌局中的倍数信息
write(16007, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_table_double, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16007, ServerData)};

%% 16008牌局结果
write(16008, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_table_result, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16008, ServerData)};

%% 16009玩家重新开始
write(16009, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_player_restart, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16009, ServerData)};

%% 16010玩家退出斗地主
write(16010, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_player_leave, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16010, ServerData)};

%% 16011确定玩家身份和底牌
write(16011, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_table_cards, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16011, ServerData)};

%% 16012 玩家设置托管
write(16012, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_player_trust, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16012, ServerData)};

%% 16013 玩家发表情
write(16013, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_player_emoticon, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16013, ServerData)};

%% 16014 获取比赛场信息
write(16014, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_get_match_info, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16014, ServerData)};

%% 16015 报名参加比赛场
write(16015, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_enroll_match, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16015, ServerData)};

%% 16016 报名人数
write(16016, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_enroll_number, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16016, ServerData)};

%% 16017 取消报名比赛场
write(16017, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_cancel_match, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16017, ServerData)};

%% 16018比赛等待匹配中
write(16018, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_wait_match, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16018, ServerData)};

%% 16019获取比赛局数信息
write(16019, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_get_match_turn_info, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16019, ServerData)};

%% 16020 比赛结果
write(16020, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_match_result, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16020, ServerData)};

%% 16021 比赛结果
write(16021, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_match_change_point, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16021, ServerData)};

%% 16022 自己的牌局任务
write(16022, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_poke_task, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16022, ServerData)};

%% 16023 完成牌局任务
write(16023, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_finish_poke_task, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16023, ServerData)};

%% 16024 使用记牌器
write(16024, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_poke_use_note, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16024, ServerData)};

%% 16026 使用记牌器
write(16026, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_player_box_num, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16026, ServerData)};

%% 16027 获取房间人数
write(16027, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_poke_room_num, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16027, ServerData)};

%% 16028 玩家触发技能buff
write(16028, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_trigger_skill, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16028, ServerData)};

%% 16029 通知玩家准备开始实物大奖赛
write(16029, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_notice_ready_match, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16029, ServerData)};

%% 16030 玩家准备开始实物大奖赛
write(16030, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_ready_match, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16030, ServerData)};

%% 16031 透视卡使用
write(16031, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_poke_use_show, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16031, ServerData)};

%% 16032 牌桌玩家状态
write(16032, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_poke_player_state, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16032, ServerData)};

%% 16033 配桌信息通知
write(16033, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_poke_table_notify, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16033, ServerData)};

%% 16035 牌桌信息
write(16035, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_poke_round_notify, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16035, ServerData)};

%% 16040 玩家退出房间通知
write(16040, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_logout_room, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(16040, ServerData)};

write(Cmd, _R) ->
    ?ERROR_MSG("~s pt_10 writting cmd_[~p], Data:~p~n",[misc:time_format(game_timer:now()), Cmd, _R]),
    {ok, pt:pack(0, <<>>)}.


	
